------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:/Users/silvio/Documents/CVR/ryp/output/s1_data_prep.log
  log type:  text
 opened on:  20 Nov 2018, 14:49:35

. clear

. 
. *****************************************
. *Geocode file from the INEI
. *****************************************
. insheet using "$odata1/ubigeo2002.csv"
(4 vars, 2048 obs)

. *insheet using ubigeo2002.txt
. ren  coddpto idepa

. ren  codprov iprov

. ren  coddist idist

. replace idepa=int(idepa)
(0 real changes made)

. replace iprov=int(iprov)
(0 real changes made)

. replace idist=int(idist)
(0 real changes made)

. gen i=idepa*1000+iprov*100+idist

. 
. ren nombre lugar

. sort idepa iprov idist

. save "$data/ubigeo2002", replace
file C:/Users/silvio/Documents/CVR/ryp/data/ubigeo2002.dta saved

. clear

. *****************************************
. 
. *****************************************
. * Original dataset
. *****************************************
. insheet using "$odata/IntermuestraV1-2.csv"
(17 vars, 24692 obs)

. 
. *Keeping the order
. gen id=_n

. 
. gen perpe=3     

. replace perpe=1 if agente=="EST" | agente=="PAR" | agente=="RON"
(11564 real changes made)

. replace perpe=2 if agente=="SLU"
(9243 real changes made)

. 
. label variable perpe "Perpetrador"

. label def perpe 1 "EST"  2 "SLU" 3 "OTH"

. label values perpe perpe

. 
. *Table 3 of BASM 
. tab cvr dp if odh==0 & perpe==0
no observations

. tab cvr dp if odh==0 & perpe==1

           |          DP
       CVR |         0          1 |     Total
-----------+----------------------+----------
         0 |         0      1,639 |     1,639 
         1 |     3,888        554 |     4,442 
-----------+----------------------+----------
     Total |     3,888      2,193 |     6,081 


. tab cvr dp if odh==0 & perpe==2

           |          DP
       CVR |         0          1 |     Total
-----------+----------------------+----------
         0 |         0         35 |        35 
         1 |     8,768         59 |     8,827 
-----------+----------------------+----------
     Total |     8,768         94 |     8,862 


. 
. tab cvr dp if odh==1 & perpe==0
no observations

. tab cvr dp if odh==1 & perpe==1

           |          DP
       CVR |         0          1 |     Total
-----------+----------------------+----------
         0 |     2,532      1,140 |     3,672 
         1 |       627      1,184 |     1,811 
-----------+----------------------+----------
     Total |     3,159      2,324 |     5,483 


. tab cvr dp if odh==1 & perpe==2

           |          DP
       CVR |         0          1 |     Total
-----------+----------------------+----------
         0 |       251          2 |       253 
         1 |       105         23 |       128 
-----------+----------------------+----------
     Total |       356         25 |       381 


. 
. gen perpe1=perpe

. replace perpe1=4 if agente==""
(1648 real changes made)

. replace perpe1=4 if agente=="NOD"
(1288 real changes made)

. replace perpe1=4 if agente=="ENF"
(139 real changes made)

. replace perpe1=4 if agente=="EMR"
(68 real changes made)

. replace perpe1=4 if agente=="ESL"
(256 real changes made)

. 
. gen perpe2=perpe1

. replace perpe2=. if perpe2==4
(3399 real changes made, 3399 to missing)

. 
. g miss=(perpe1==4)

. 
. g age= anohechos- anonac
(7180 missing values generated)

. replace age=. if age<0 | age>110
(8 real changes made, 8 to missing)

. 
. g situa=0 if situacion=="DES"
(14820 missing values generated)

. replace situa=1 if situacion=="MUE"
(14820 real changes made)

. 
. 
. ************************************************
. *We construct the 58 strata of BASM using the GeoCode of INEI
. ************************************************
. * We eliminate first the last four digits of "Ubihechos", which are not used anyway.
. ************************************************
. gen i=ubihechos/10000
(687 missing values generated)

. replace i=int(i)
(4891 real changes made)

. gen idepa=int(i/10000)
(687 missing values generated)

. gen iprov=int((i-idepa*10000)/100)
(687 missing values generated)

. gen idist=int(i-idepa*10000-iprov*100)
(687 missing values generated)

. 
. sort idepa iprov idist

. 
. merge idepa iprov idist using "$data/ubigeo2002"
(note: you are using old merge syntax; see [D] merge for new syntax)
variables idepa iprov idist do not uniquely identify observations in the master data

. drop if _merge==2
(1173 observations deleted)

. sort id

. drop _merge

. save "$data/cvrextrapo", replace
file C:/Users/silvio/Documents/CVR/ryp/data/cvrextrapo.dta saved

. 
. do "$code/strata58" /*Creates j that defines 58 strata of BASM*/

. ************************************************
. *We construct now the 58 strata of BASM
. ************************************************
. gen j=.
(24692 missing values generated)

. 
. *1. Loreto, Ucayali, Madre de Dios 
. replace j=1 if idepa==16 
(69 real changes made)

. replace j=1 if idepa==25 
(587 real changes made)

. replace j=1 if idepa==17 
(1 real change made)

. 
. *2. Callao
. replace j=2 if idepa==7
(48 real changes made)

. 
. *3. Ancash (Bolognesi,Ocros)
. replace j=3 if idepa==2 & iprov==5 
(41 real changes made)

. replace j=3 if idepa==2 & iprov==14 
(25 real changes made)

. 
. *4. Ancash (Huaraz, Huaylas, Mariscal Luzuriaga, Pallasca, Santa, Sihuas, Pomabamba, Recuay, Asuncion, Carhuaz, Aija, Antoni
> o Raymondi, Carlos F. Fitzcarrald, Huari, Huarmey, Casma, Corongo, Yungay)
. *replace j=4 if idepa==2 & j~=3
. replace j=4 if idepa==2 & iprov==1
(40 real changes made)

. replace j=4 if idepa==2 & iprov==2
(0 real changes made)

. replace j=4 if idepa==2 & iprov==3
(1 real change made)

. replace j=4 if idepa==2 & iprov==4
(0 real changes made)

. replace j=4 if idepa==2 & iprov==6
(11 real changes made)

. replace j=4 if idepa==2 & iprov==7
(1 real change made)

. replace j=4 if idepa==2 & iprov==8
(0 real changes made)

. replace j=4 if idepa==2 & iprov==9
(6 real changes made)

. replace j=4 if idepa==2 & iprov==10
(42 real changes made)

. replace j=4 if idepa==2 & iprov==11
(0 real changes made)

. replace j=4 if idepa==2 & iprov==12
(0 real changes made)

. replace j=4 if idepa==2 & iprov==13
(0 real changes made)

. replace j=4 if idepa==2 & iprov==15
(2 real changes made)

. replace j=4 if idepa==2 & iprov==16
(0 real changes made)

. replace j=4 if idepa==2 & iprov==17
(17 real changes made)

. replace j=4 if idepa==2 & iprov==18
(17 real changes made)

. replace j=4 if idepa==2 & iprov==19
(2 real changes made)

. replace j=4 if idepa==2 & iprov==20
(4 real changes made)

. 
. *5. Arequipa, Moquegua, La Libertad, Lambayeque, Piura, Ica, Tacna, Tumbes
. replace j=5 if idepa==4 | idepa==18 | idepa==13 | idepa==14 | idepa==18 | idepa==20 | idepa==11 | idepa==23 | idepa==24
(234 real changes made)

. 
. *6. Lima (Oyon, Cajatambo)
. replace j=6 if idepa==15 & iprov==9
(14 real changes made)

. replace j=6 if idepa==15 & iprov==3
(29 real changes made)

. 
. *7. Lima (Huaura, Huarochiri, Huaral, Canta, Barranca)
. replace j=7 if idepa==15 & iprov==8
(49 real changes made)

. replace j=7 if idepa==15 & iprov==7
(4 real changes made)

. replace j=7 if idepa==15 & iprov==6
(6 real changes made)

. replace j=7 if idepa==15 & iprov==4
(1 real change made)

. replace j=7 if idepa==15 & iprov==2
(11 real changes made)

. 
. * 8. Lima (Lima [Rimac, San Martin de Porres, Villa el Salvador, San Juan de Miraflores])
. replace j=8 if idepa==15 & iprov==1 & idist==28
(5 real changes made)

. replace j=8 if idepa==15 & iprov==1 & idist==35
(16 real changes made)

. replace j=8 if idepa==15 & iprov==1 & idist==42
(13 real changes made)

. replace j=8 if idepa==15 & iprov==1 & idist==33
(5 real changes made)

. 
. * 9. Lima (Lima [Carabayllo, Miraflores, Magdalena Vieja, Magdalena del Mar, Jesus Maria, Comas, Independencia, El Agustino,
>  
. *Los Olivos, Lince, La Victoria, La Molina, Puente Piedra, Surquillo, Santiago de Surco, Bre.a, Lima, Ate, Villa Maria del T
> riunfo,
. *Santa Anita, San Juan de Lurigancho, San Isidro, San Borja, San Miguel, San Luis,
. *San Bartolo]
. *replace j=9 if idepa==15 & iprov==1 & j~=8
. replace j=9 if idepa==15 & iprov==1 & idist==1
(70 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==2
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==3
(19 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==4
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==5
(3 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==6
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==7
(4 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==8
(7 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==9
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==10
(10 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==11
(9 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==12
(3 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==13
(2 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==14
(4 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==15
(3 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==16
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==17
(15 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==18
(13 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==19
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==20
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==21
(5 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==22
(5 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==23
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==24
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==25
(2 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==26
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==27
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==29
(3 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==30
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==31
(5 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==32
(72 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==34
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==36
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==37
(2 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==38
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==39
(0 real changes made)

. replace j=9 if idepa==15 & iprov==1 & idist==40
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==41
(1 real change made)

. replace j=9 if idepa==15 & iprov==1 & idist==43
(9 real changes made)

. 
. 
. *10. Lima (Caqete, Yauyos)
. replace j=10 if idepa==15 & iprov==5
(0 real changes made)

. replace j=10 if idepa==15 & iprov==10
(40 real changes made)

. 
. *11. Apurimac, Cusco
. replace j=11 if idepa==3 | idepa==8 
(1479 real changes made)

. 
. *12. Amazonas, Cajamarca, San Martin (Rioja, El Dorado, Moyobamba, Lamas, Huallaga)
. replace j=12 if idepa==1
(18 real changes made)

. replace j=12 if idepa==6
(55 real changes made)

. replace j=12 if idepa==22 & iprov==8
(26 real changes made)

. replace j=12 if idepa==22 & iprov==3
(43 real changes made)

. replace j=12 if idepa==22 & iprov==1
(49 real changes made)

. replace j=12 if idepa==22 & iprov==5
(85 real changes made)

. replace j=12 if idepa==22 & iprov==4
(21 real changes made)

. 
. *13. San Martin (Picota, Bellavista)
. replace j=13 if idepa==22 & iprov==7
(29 real changes made)

. replace j=13 if idepa==22 & iprov==2
(28 real changes made)

. 
. *14. Huanuco, San Martin (Mariscal Caceres, Tocache)
. replace j=14 if idepa==10
(2566 real changes made)

. replace j=14 if idepa==22 & iprov==6
(121 real changes made)

. replace j=14 if idepa==22 & iprov==10
(532 real changes made)

. 
. *15. Pasco
. replace j=15 if idepa==19
(264 real changes made)

. 
. *16. Ayacucho (Parinacochas, Paucar del Sara Sara)
. replace j=16 if idepa==5 & iprov==7
(59 real changes made)

. replace j=16 if idepa==5 & iprov==8
(28 real changes made)

. 
. 
. *17. Ayacucho (Lucanas [Aucara, Chavipa, Chipao, Laramate, Carmen Salcedo, Cabana])
. replace j=17 if idepa==5 & iprov==6 & idist==2
(70 real changes made)

. replace j=17 if idepa==5 & iprov==6 & idist==5
(2 real changes made)

. replace j=17 if idepa==5 & iprov==6 & idist==6
(12 real changes made)

. replace j=17 if idepa==5 & iprov==6 & idist==8
(2 real changes made)

. replace j=17 if idepa==5 & iprov==6 & idist==4
(16 real changes made)

. replace j=17 if idepa==5 & iprov==6 & idist==3
(15 real changes made)

. 
. * 18. Ayacucho (Lucanas [San Pedro, Puquio, San Pedro de Palco, Santa Ana de Huaycahuacho, Leoncio Prado, San Juan, Lucanas]
> )
. *replace j=18 if idepa==5 & iprov==6 & j~=17
. replace j=18 if idepa==5 & iprov==6 & idist==17
(3 real changes made)

. replace j=18 if idepa==5 & iprov==6 & idist==1
(30 real changes made)

. replace j=18 if idepa==5 & iprov==6 & idist==18
(3 real changes made)

. replace j=18 if idepa==5 & iprov==6 & idist==20
(8 real changes made)

. replace j=18 if idepa==5 & iprov==6 & idist==9
(1 real change made)

. replace j=18 if idepa==5 & iprov==6 & idist==16
(8 real changes made)

. replace j=18 if idepa==5 & iprov==6 & idist==11
(24 real changes made)

. 
. *19. Ayacucho (Huanta [Ayahuanco, Huamanguilla, Llochegua])
. replace j=19 if idepa==5 & iprov==4 & idist==2
(234 real changes made)

. replace j=19 if idepa==5 & iprov==4 & idist==3
(79 real changes made)

. replace j=19 if idepa==5 & iprov==4 & idist==8
(50 real changes made)

.         
. *Ayacucho (Huanta [Huanta])
. replace j=20 if idepa==5 & iprov==4 & idist==1
(777 real changes made)

. *Assumption
. *replace j=20 if idepa==5 & iprov==4 & idist==0
.         
. 
. *Ayacucho (Huanta [Iguain])
. replace j=21 if idepa==5 & iprov==4 & idist==4
(112 real changes made)

. *Ayacucho (Huanta [Luricocha])
. replace j=22 if idepa==5 & iprov==4 & idist==5
(136 real changes made)

. 
. * Ayacucho (Huanta [Santillana])
. replace j=23 if idepa==5 & iprov==4 & idist==6
(399 real changes made)

. 
. * Ayacucho (Huanta [Sivia])
. replace j=24 if idepa==5 & iprov==4 & idist==7
(212 real changes made)

. 
. * Ayacucho (La Mar [Chungui, Luis Carranza])
. replace j=25 if idepa==5 & iprov==5 & idist==5
(1366 real changes made)

. replace j=25 if idepa==5 & iprov==5 & idist==6
(43 real changes made)

. *Assumption
. *replace j=25 if idepa==5 & iprov==5 & idist==0
. 
. 
. * Ayacucho (La Mar [San Miguel])
. replace j=26 if idepa==5 & iprov==5 & idist==1
(425 real changes made)

. 
. * Ayacucho (La Mar [Anco])
. replace j=27 if idepa==5 & iprov==5 & idist==2
(241 real changes made)

. 
. * Ayacucho (La Mar [Ayna])
. replace j=28 if idepa==5 & iprov==5 & idist==3
(254 real changes made)

. 
. * Ayacucho (La Mar [Chilcas])
. replace j=29 if idepa==5 & iprov==5 & idist==4
(151 real changes made)

. 
. * Ayacucho (La Mar [Santa Rosa])
. replace j=30 if idepa==5 & iprov==5 & idist==7
(264 real changes made)

. 
. * Ayacucho (La Mar [Tambo])
. replace j=31 if idepa==5 & iprov==5 & idist==8
(447 real changes made)

. 
. * Ayacucho (Cangallo)
. replace j=32 if idepa==5 & iprov==2
(598 real changes made)

. 
. * Ayacucho (Huanca Sancos)
. replace j=33 if idepa==5 & iprov==3
(312 real changes made)

. 
. * Ayacucho (Sucre)
. replace j=34 if idepa==5 & iprov==9
(184 real changes made)

. 
. * Ayacucho (Victor Fajardo)
. replace j=35 if idepa==5 & iprov==10
(785 real changes made)

. 
. * Ayacucho (Vilcas Huaman)
. replace j=36 if idepa==5 & iprov==11
(1124 real changes made)

. 
. * Ayacucho (Huamanga [Quinua, Ayacucho, Pacaycasa, Jesus Nazareno, Ocros])
. replace j=37 if idepa==5 & iprov==1 & idist==8
(88 real changes made)

. replace j=37 if idepa==5 & iprov==1 & idist==1
(519 real changes made)

. replace j=37 if idepa==5 & iprov==1 & idist==7
(37 real changes made)

. replace j=37 if idepa==5 & iprov==1 & idist==15
(19 real changes made)

. replace j=37 if idepa==5 & iprov==1 & idist==6
(69 real changes made)

. *Assumption
. *replace j=37 if idepa==5 & iprov==0 & idist==0
. *replace j=37 if idepa==5 & iprov==1 & idist==0
. 
. 
. 
. * Ayacucho (Huamanga [Acos Vinchos])
. replace j=38 if idepa==5 & iprov==1 & idist==3
(31 real changes made)

. 
. * Ayacucho (Huamanga [Carmen Alto])
. replace j=39 if idepa==5 & iprov==1 & idist==4
(55 real changes made)

. 
. * Ayacucho (Huamanga [Santiago de Pischa, Acocro])
. replace j=40 if idepa==5 & iprov==1 & idist==11
(155 real changes made)

. replace j=40 if idepa==5 & iprov==1 & idist==2
(237 real changes made)

. 
. * Ayacucho (Huamanga [Chiara])
. replace j=41 if idepa==5 & iprov==1 & idist==5
(145 real changes made)

. 
. * Ayacucho (Huamanga [San Jose de Ticllas])
. replace j=42 if idepa==5 & iprov==1 & idist==9
(156 real changes made)

. 
. * Ayacucho (Huamanga [San Juan Bautista])
. replace j=43 if idepa==5 & iprov==1 & idist==10
(121 real changes made)

. 
. * Ayacucho (Huamanga [Socos])
. replace j=44 if idepa==5 & iprov==1 & idist==12
(51 real changes made)

. 
. * Huancavelica (Huancavelica, Tayacaja, Acobamba, Churcampa)
. replace j=45 if idepa==9 & iprov==1 
(473 real changes made)

. replace j=45 if idepa==9 & iprov==7
(91 real changes made)

. replace j=45 if idepa==9 & iprov==2
(69 real changes made)

. replace j=45 if idepa==9 & iprov==5
(258 real changes made)

. 
. * Ayacucho (Huamanga [Vinchos])
. replace j=46 if idepa==5 & iprov==1 & idist==14
(204 real changes made)

. 
. 
. *Puno
. replace j=47 if idepa==21
(430 real changes made)

. 
. * Huancavelica (Huaytara, Angaraes)
. replace j=48 if idepa==9 & iprov==6
(45 real changes made)

. replace j=48 if idepa==9 & iprov==3
(471 real changes made)

. 
. * Ayacucho (Huamanga [Tambillo])
. replace j=49 if idepa==5 & iprov==1 & idist==13
(36 real changes made)

. 
. * Huancavelica (Castrovirreyna)
. replace j=50 if idepa==9 & iprov==4
(123 real changes made)

.         
. * Junin (Junin, Tarma, Yauli, Chanchamayo)
. replace j=51 if idepa==12 & iprov==5
(81 real changes made)

. replace j=51 if idepa==12 & iprov==7
(141 real changes made)

. replace j=51 if idepa==12 & iprov==8
(24 real changes made)

. replace j=51 if idepa==12 & iprov==3
(326 real changes made)

. 
. 
. * Junin (Jauja, Concepcion, Chupaca)
. replace j=52 if idepa==12 & iprov==4
(159 real changes made)

. replace j=52 if idepa==12 & iprov==2
(202 real changes made)

. replace j=52 if idepa==12 & iprov==9
(87 real changes made)

. 
. * Junin (Huancayo [Huancayo])
. replace j=53 if idepa==12 & iprov==1 & idist==1
(142 real changes made)

. 
. * Junin (Huancayo [Chilca])
. replace j=54 if idepa==12 & iprov==1  & idist==7
(34 real changes made)

. 
. * Junin (Huancayo [El Tambo])
. replace j=55 if idepa==12 & iprov==1  & idist==14
(89 real changes made)

. 
. * Junin (Huancayo [Chupuro, Huayucachi, Hualhuas, Huacrapuquio, Cullhuas,Huasicancha, Huancan, Colca, Sanyo, Santo Domingo d
> e Acobamba, Viques, Sapallanga, Sicaya, Chicche, Chongos Alto, Carhuacallanga, Ingenio, Pucara, Quichuay, Pariahuanca, SanAg
> ustin, San Jeronimo de Tunan, Chacapampa, Pilcomayo, Quilcas])
. *replace j=56 if idepa==12 & iprov==1 & idist~=1 & idist~=7 & idist~=14
. replace j=56 if idepa==12 & iprov==1 & idist==11
(2 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==21
(1 real change made)

. replace j=56 if idepa==12 & iprov==1 & idist==17
(1 real change made)

. replace j=56 if idepa==12 & iprov==1 & idist==16
(2 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==13
(0 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==20
(3 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==19
(5 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==12
(2 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==32
(4 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==35
(42 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==36
(5 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==33
(3 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==34
(1 real change made)

. replace j=56 if idepa==12 & iprov==1 & idist==6
(7 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==8
(17 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==4
(0 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==22
(5 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==26
(13 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==27
(0 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==24
(42 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==29
(2 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==30
(0 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==5
(8 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==25
(2 real changes made)

. replace j=56 if idepa==12 & iprov==1 & idist==28
(3 real changes made)

. 
. * Junin (Satipo)
. replace j=57 if idepa==12 & iprov==6
(1082 real changes made)

. 
. * San Martin (San Martin)
. replace j=58 if idepa==22 & iprov==9
(125 real changes made)

. *Assumption
. *replace j=58 if idepa==22 & iprov==0
. 
. 
. label variable j "Locations"

. label def loca 1 "1 Loreto, Ucayali, Madre de Dios", add

. label def loca 2 "2 Callao", add

. label def loca 3 "3 Ancash (Orcos, Bolognesi)", add

. label def loca 4 "4 Ancash (Rest)", add

. label def loca 5 "5 Arequipa, Moquegua, La Libertad, Lambayeque, Piura, Ica, Tacna, Tumbes", add

. label def loca 6 "6 Lima (Oyon, Cajatambo)", add

. label def loca 7 "7 Lima (Huaura, Huarochiri, Huaral, Canta, Barranca)", add

. label def loca 8 "8 Lima (Lima [Rimac, San Martin de Porres, Villa el Salvador, San Juan de Miraflores])", add

. label def loca 9 "9 Lima (Lima [Rest])", add

. label def loca 10 "10 Lima (Canyete, Yauyos)", add

. label def loca 11 "11 Apurimac, Cusco", add

. label def loca 12 "12 Amazonas, Cajamarca, San Martin (Rioja, El Dorado, Moyobamba, Lamas, Huallaga)", add

. label def loca 13 "13 San Martin (Picota, Bella vista)", add

. label def loca 14 "14 Huanuco, San Martin (Mariscal Caceres, Tocache)", add

. label def loca 15 "15 Pasco", add

. label def loca 16 "16 Ayacucho (Parinacochas, Paucar del Sara Sara)", add

. label def loca 17 "17 Ayacucho (Lucanas [Aucara, Chavipa, Chipao, Laramate, Carmen Salcedo, Cabana])", add

. label def loca 18 "18 Ayacucho (Lucanas [Rest])", add

. label def loca 19 "19 Ayacucho (Huanta [Ayahuanco, Huamanguilla, Llochegua])", add

. label def loca 20 "20 Ayachuco (Huanta [Huanta])", add

. label def loca 21 "21 Ayacucho (Huanta [Iguain])", add

. label def loca 22 "22 Ayacucho (Huanta [Luricocha])", add

. label def loca 23 "23 Ayacucho (Huanta [Santillana])", add

. label def loca 24 "24 Ayacucho (Huanta [Sivia])", add

. label def loca 25 "25 Ayacucho (La Mar [Chungui, Luis Carranza])", add

. label def loca 26 "26 Ayacucho (La Mar [San Miguel])", add

. label def loca 27 "27 Ayacucho (La Mar [Anco])", add

. label def loca 28 "28 Ayacucho (La Mar [Ayna])", add

. label def loca 29 "29 Ayacucho (La Mar [Chilcas])", add

. label def loca 30 "30 Ayacucho (La Mar [Santa Rosa])", add

. label def loca 31 "31 Ayacucho (La Mar [Tambo])", add

. label def loca 32 "32 Ayacucho (Cangallo)", add

. label def loca 33 "33 Ayacucho (Huanca Sancos)", add

. label def loca 34 "34 Ayacucho (Sucre)", add

. label def loca 35 "35 Ayacucho (Victor Fajardo)", add

. label def loca 36 "36 Ayacucho (Vilcas Huaman)", add

. label def loca 37 "37 Ayacucho (Huamanga [Quinua, Ayacucho, Pacaycasa, JNazareno, Orcos])", add

. label def loca 38 "38 Ayacucho (Huamanga [Acos Vinchos])", add

. label def loca 39 "39 Ayacucho (Huamanga [Carmen Alto])", add

. label def loca 40 "40 Ayacucho (Huamanga [Santiago de Pischa, Acocro])", add

. label def loca 41 "41 Ayacucho (Huamanga [Chiara])", add

. label def loca 42 "42 Ayacucho (Huamanga [San Jose de Ticllas])", add

. label def loca 43 "43 Ayacucho (Huamanga [San Juan Bautista])", add

. label def loca 44 "44 Ayacucho (Huamanga [Socos])", add

. label def loca 45 "45 Huancavelica (Huancavelica, Tayacaja, Acobamba, Churcampa)", add

. label def loca 46 "46 Ayacucho (Huamanga [Vinchos])", add

. label def loca 47 "47 Puno", add

. label def loca 48 "48 Huancavelica (Huaytara, Angaraes)", add

. label def loca 49 "49 Ayacucho (Huamanga [Tambillo])", add

. label def loca 50 "50 Huancavelica (Castrovirreyna)", add

. label def loca 51 "51 Junin (Junin, Tarma, Yauli, Chanchamayo)", add

. label def loca 52 "52 Junin (Jauja, Concepcion, Chupaca)", add

. label def loca 53 "53 Junin (Huancayo [Huancayo])", add

. label def loca 54 "54 Junin (Huancayo [Chilca])", add

. label def loca 55 "55 Junin (Huancayo [El Tambo])", add

. label def loca 56 "56 Junin (Huancayo [Rest])", add     

. label def loca 57  "57 Junin (Satipo)", add

. label def loca 58 "58 San Martin (San Martin)", add

. label values j loca

. 
. ************************************************
. * Strata done
. ************************************************
. 
end of do-file

. 
. gen source=4*odh+2*dp+cvr+1

. gen sl=0

. replace sl=1 if perpe==2
(9243 real changes made)

. gen esta=0      

. replace esta=1 if perpe==1
(11564 real changes made)

. gen source1=0

. replace source1=1 if source==2
(15794 real changes made)

. 
. gen sexon=0

. replace sexon=1 if sexo=="F"
(4661 real changes made)

. label variable sexon "Sexo"

. label def sexon 0 "Male" 1 "Female"

. label values sexon sexon

. 
. 
. 
. gen i2=ubihechos-i*10000
(687 missing values generated)

. 
. 
. g excluded=j==.

. g otheri=perpe2==3 if perpe==3
(20807 missing values generated)

. label def other 0 "Missing" 1 "Identified"

. label values otheri other

. label def excludedl 0 "In TRC Strata" 1 "Excluded"

. label values excluded excludedl

. label var otheri "Other"

. label def sourcel 2 "C" 3 "D" 4 "CD"    5 "N" 6 "CN" 7  "DN" 8 "CDN"

. la val source sourcel

. 
. * Table 1
. tab perpe source

Perpetrado |                                    source
         r |         C          D         CD          N         CN         DN        CDN |     Total
-----------+-----------------------------------------------------------------------------+----------
       EST |     3,888      1,639        554      2,532        627      1,140      1,184 |    11,564 
       SLU |     8,768         35         59        251        105          2         23 |     9,243 
       OTH |     3,138         49         10        571         34         76          7 |     3,885 
-----------+-----------------------------------------------------------------------------+----------
     Total |    15,794      1,723        623      3,354        766      1,218      1,214 |    24,692 


. tab otheri source

           |                                    source
     Other |         C          D         CD          N         CN         DN        CDN |     Total
-----------+-----------------------------------------------------------------------------+----------
   Missing |     2,857         47          8        446         22         13          6 |     3,399 
Identified |       281          2          2        125         12         63          1 |       486 
-----------+-----------------------------------------------------------------------------+----------
     Total |     3,138         49         10        571         34         76          7 |     3,885 


. 
. * Table 2
. tab perpe excluded

Perpetrado |       excluded
         r | In TRC St   Excluded |     Total
-----------+----------------------+----------
       EST |     9,566      1,998 |    11,564 
       SLU |     9,075        168 |     9,243 
       OTH |     3,309        576 |     3,885 
-----------+----------------------+----------
     Total |    21,950      2,742 |    24,692 


. tab otheri excluded

           |       excluded
     Other | In TRC St   Excluded |     Total
-----------+----------------------+----------
   Missing |     2,944        455 |     3,399 
Identified |       365        121 |       486 
-----------+----------------------+----------
     Total |     3,309        576 |     3,885 


. 
. * Table 4
. tab j perpe

                      |           Perpetrador
            Locations |       EST        SLU        OTH |     Total
----------------------+---------------------------------+----------
1 Loreto, Ucayali, Ma |       367        151        139 |       657 
             2 Callao |        42          1          5 |        48 
3 Ancash (Orcos, Bolo |        29         23         14 |        66 
      4 Ancash (Rest) |        57         46         40 |       143 
5 Arequipa, Moquegua, |        71        105         58 |       234 
6 Lima (Oyon, Cajatam |        22         18          3 |        43 
7 Lima (Huaura, Huaro |        40         12         19 |        71 
8 Lima (Lima [Rimac,  |        23          5         11 |        39 
 9 Lima (Lima [Rest]) |       185         36         53 |       274 
10 Lima (Canyete, Yau |        19         21          0 |        40 
   11 Apurimac, Cusco |       675        570        234 |     1,479 
12 Amazonas, Cajamarc |       141         32        124 |       297 
13 San Martin (Picota |        12         12         33 |        57 
14 Huanuco, San Marti |     1,260      1,270        689 |     3,219 
             15 Pasco |        68         95        101 |       264 
16 Ayacucho (Parinaco |        26         52          9 |        87 
17 Ayacucho (Lucanas  |        47         57         13 |       117 
18 Ayacucho (Lucanas  |        17         54          6 |        77 
19 Ayacucho (Huanta [ |       168        166         29 |       363 
20 Ayachuco (Huanta [ |       341        347         89 |       777 
21 Ayacucho (Huanta [ |        68         23         21 |       112 
22 Ayacucho (Huanta [ |        68         60          8 |       136 
23 Ayacucho (Huanta [ |       199        174         26 |       399 
24 Ayacucho (Huanta [ |        37        130         45 |       212 
25 Ayacucho (La Mar [ |       956        422         31 |     1,409 
26 Ayacucho (La Mar [ |       156        205         64 |       425 
27 Ayacucho (La Mar [ |        68        127         46 |       241 
28 Ayacucho (La Mar [ |       144         82         28 |       254 
29 Ayacucho (La Mar [ |        47         98          6 |       151 
30 Ayacucho (La Mar [ |        72        132         60 |       264 
31 Ayacucho (La Mar [ |       161        252         34 |       447 
32 Ayacucho (Cangallo |       378        163         57 |       598 
33 Ayacucho (Huanca S |        89        190         33 |       312 
  34 Ayacucho (Sucre) |        62        114          8 |       184 
35 Ayacucho (Victor F |       436        246        103 |       785 
36 Ayacucho (Vilcas H |       623        426         75 |     1,124 
37 Ayacucho (Huamanga |       489        169         74 |       732 
38 Ayacucho (Huamanga |        17         12          2 |        31 
39 Ayacucho (Huamanga |        32         21          2 |        55 
40 Ayacucho (Huamanga |       137        225         30 |       392 
41 Ayacucho (Huamanga |       101         21         23 |       145 
42 Ayacucho (Huamanga |        55         81         20 |       156 
43 Ayacucho (Huamanga |        79         28         14 |       121 
44 Ayacucho (Huamanga |        43          6          2 |        51 
45 Huancavelica (Huan |       362        409        120 |       891 
46 Ayacucho (Huamanga |        70        123         11 |       204 
              47 Puno |        91        258         81 |       430 
48 Huancavelica (Huay |       145        320         51 |       516 
49 Ayacucho (Huamanga |        23          8          5 |        36 
50 Huancavelica (Cast |        35         82          6 |       123 
51 Junin (Junin, Tarm |       111        321        140 |       572 
52 Junin (Jauja, Conc |       170        159        119 |       448 
53 Junin (Huancayo [H |        94         27         21 |       142 
54 Junin (Huancayo [C |        19          7          8 |        34 
55 Junin (Huancayo [E |        48         26         15 |        89 
56 Junin (Huancayo [R |        60         72         38 |       170 
    57 Junin (Satipo) |       139        776        167 |     1,082 
58 San Martin (San Ma |        72          7         46 |       125 
----------------------+---------------------------------+----------
                Total |     9,566      9,075      3,309 |    21,950 


. tab j otheri

                      |         Other
            Locations |   Missing  Identifie |     Total
----------------------+----------------------+----------
1 Loreto, Ucayali, Ma |       110         29 |       139 
             2 Callao |         3          2 |         5 
3 Ancash (Orcos, Bolo |        14          0 |        14 
      4 Ancash (Rest) |        38          2 |        40 
5 Arequipa, Moquegua, |        55          3 |        58 
6 Lima (Oyon, Cajatam |         3          0 |         3 
7 Lima (Huaura, Huaro |        15          4 |        19 
8 Lima (Lima [Rimac,  |         8          3 |        11 
 9 Lima (Lima [Rest]) |        50          3 |        53 
   11 Apurimac, Cusco |       223         11 |       234 
12 Amazonas, Cajamarc |        75         49 |       124 
13 San Martin (Picota |        18         15 |        33 
14 Huanuco, San Marti |       657         32 |       689 
             15 Pasco |        97          4 |       101 
16 Ayacucho (Parinaco |         8          1 |         9 
17 Ayacucho (Lucanas  |        13          0 |        13 
18 Ayacucho (Lucanas  |         6          0 |         6 
19 Ayacucho (Huanta [ |        29          0 |        29 
20 Ayachuco (Huanta [ |        88          1 |        89 
21 Ayacucho (Huanta [ |        20          1 |        21 
22 Ayacucho (Huanta [ |         7          1 |         8 
23 Ayacucho (Huanta [ |        25          1 |        26 
24 Ayacucho (Huanta [ |        45          0 |        45 
25 Ayacucho (La Mar [ |        29          2 |        31 
26 Ayacucho (La Mar [ |        62          2 |        64 
27 Ayacucho (La Mar [ |        46          0 |        46 
28 Ayacucho (La Mar [ |        25          3 |        28 
29 Ayacucho (La Mar [ |         6          0 |         6 
30 Ayacucho (La Mar [ |        59          1 |        60 
31 Ayacucho (La Mar [ |        33          1 |        34 
32 Ayacucho (Cangallo |        46         11 |        57 
33 Ayacucho (Huanca S |        26          7 |        33 
  34 Ayacucho (Sucre) |         7          1 |         8 
35 Ayacucho (Victor F |        98          5 |       103 
36 Ayacucho (Vilcas H |        65         10 |        75 
37 Ayacucho (Huamanga |        64         10 |        74 
38 Ayacucho (Huamanga |         2          0 |         2 
39 Ayacucho (Huamanga |         1          1 |         2 
40 Ayacucho (Huamanga |        28          2 |        30 
41 Ayacucho (Huamanga |        20          3 |        23 
42 Ayacucho (Huamanga |        20          0 |        20 
43 Ayacucho (Huamanga |        10          4 |        14 
44 Ayacucho (Huamanga |         2          0 |         2 
45 Huancavelica (Huan |       116          4 |       120 
46 Ayacucho (Huamanga |        11          0 |        11 
              47 Puno |        79          2 |        81 
48 Huancavelica (Huay |        49          2 |        51 
49 Ayacucho (Huamanga |         3          2 |         5 
50 Huancavelica (Cast |         6          0 |         6 
51 Junin (Junin, Tarm |        78         62 |       140 
52 Junin (Jauja, Conc |       100         19 |       119 
53 Junin (Huancayo [H |        19          2 |        21 
54 Junin (Huancayo [C |         7          1 |         8 
55 Junin (Huancayo [E |        14          1 |        15 
56 Junin (Huancayo [R |        25         13 |        38 
    57 Junin (Satipo) |       151         16 |       167 
58 San Martin (San Ma |        30         16 |        46 
----------------------+----------------------+----------
                Total |     2,944        365 |     3,309 


. 
. save "$data/cvrextrapo", replace
file C:/Users/silvio/Documents/CVR/ryp/data/cvrextrapo.dta saved

. 
. scalar nstrata=58

. 
. gen y=1

. sort j perpe source

. collapse (sum) y, by(perpe j source)

. 
. replace source=source-1
(683 real changes made)

. drop if j==.
(16 observations deleted)

. drop if perpe==.
(0 observations deleted)

. 
. fillin j perpe source

. recode y (. = 0)
(y: 551 changes made)

. 
. bys j perpe: g e=1+(_N==_n)

. expand e
(174 observations created)

. replace source=8 if _n>nstrata*8*3
(0 real changes made)

. replace y=-4 if _n>nstrata*8*3
(0 real changes made)

. sort j perpe source

. drop _fillin e

. gen n=_n

. 
. 
. keep n perpe j source j y

. ren source k

. g i=j

. order n perpe i k j y 

. 
. save "$data/datacvr", replace
file C:/Users/silvio/Documents/CVR/ryp/data/datacvr.dta saved

. clear

. capture log close
